/**
 * Created by Demon-pro on 2015/7/27.
 */

var Page = function () {
    /*
    function initReadonly() {
        $("#E6,#E5,#E7").prop("readonly", true);
    }

    function update($obj) {
        var the = $obj;
        if (validate.isNotNumber(the.val())) {
            validate.addInvalid(the);
            return;
        }
        $.ajax({
            url: basePath + "tools/inner-support/update",
            type: "post",
            dataType: "json",
            data: "paramName=" + the.attr("id") + "&paramValue=" + the.val(),
            success: function () {
                validate.addValid(the);
            }
        })
    }

    function e4Handle() {
        $("#E4").on("change", function () {
            initReadonly();
            switch (parseInt($(this).val())) {
                case 1:
                    $("#E7").prop("readonly", false);
                    break;
                case 2:
                    $("#E6,#E5").prop("readonly", false);
                    break;
            }
            update($(this));
        }).change();
    }

    function updateHandle() {
        $("input[id^='E'][id!='E4']").on("blur", function () {
            update($(this));
        })
    }

    function calculateHandle() {

        $("#calE15").click(function () {
            $.get(basePath + "tools/inner-support/calE15", function (data) {
                $("#E15").val(data);
            })
        });

        $("#cal").click(function () {
            Metronic.blockUI({
                boxed: true,
                message: "计算中"
            });
            $.post(basePath + "tools/inner-support/calAll", function (data) {
                $("input").autoInject({
                    data: data,
                    mode: "id"
                });
                Metronic.unblockUI();
            })
        })
    }

    function clean(){
        $.post(basePath + "tools/inner-support/clean", function () {
        });
    }

    function initParam(){
        $("#E12,#E9").blur();
    }

    return {
        init: function () {
            e4Handle();
            updateHandle();
            calculateHandle();
            clean();
            initParam();
        }
    }

}();*/




    function initReadonly() {
        $("#E6,#E5,#E7").prop("readonly", true);
    }

    var update = function ($obj){
        validate.init($obj)
        if (validate.isNotNumber($obj.val())) {
            validate.invalid();
            return;
        }
        $.ajax({
            url: basePath + "tools/inner-support/update",
            type: "post",
            dataType: "json",
            data:{
                paramName:$obj.attr("id"),
                paramValue:$obj.val()
            }
        });
        validate.valid()
    }

    function e4Handle() {
        $("#E4").on("change", function () {
            initReadonly();
            switch (parseInt($(this).val())) {
                case 1:
                    $("#E7").prop("readonly", false);
                    break;
                case 2:
                    $("#E6,#E5").prop("readonly", false);
                    break;
            }
            update($(this));
        }).change();
    }

    var updateHandle = function (){
        $("input").on("blur",function(){
            update($(this));
        })
    }

    function calculateHandle() {

        $("#calE15").click(function () {
            $.get(basePath + "tools/inner-support/calE15", function (data) {
                $("#E15").val(data);
            })
        });

        $("#cal").click(function () {
            Metronic.blockUI({
                boxed: true,
                message: "计算中"
            });
            $.post(basePath + "tools/inner-support/calAll", function (data) {
                $("input").autoInject({
                    data: data,
                    mode: "id"
                });
                Metronic.unblockUI();
            });
        });
    }

    return{
        init:function(){
            update($("#E9"));
            update($("#E12"));
            e4Handle();
            calculateHandle();
            window.onunload = function(){
                $.post(basePath + "tools/inner-support/clean",function(){});
            };
            updateHandle();
        }
    }
}();
